class Validator {
  constructor() {
    this.validators = {}
  }

  //加入规则
  on(func) {
    if (Object.prototype.toString.call(arg) === "[object Function]") {
      this.validators[func.name] = func
     
    }else if(Object.prototype.toString.call(arg) === "[object Object]"){

    }else {
      
      throw new Error("Illegal rule.")
    }
    
  }

  remove(funcName) {
    delete this.validators[funcName]
  }

  emit(funcName, value, options) {
    if (validators.funcName === undefined) {
      throw new Error("No such rule.")
    }
    return validators[funcName].call(null, value, options)
  }
}

var vali = new Validator()

const rule = key => value => rule => rule.call(null, value, rule)

const ruleFactory = options => rule

vali.on(function number() {
  console.log(x,y)
  return 123123
})

// vali.emit('dodo', 1,3)

vali.on(v => {
  console.log("v")
  return v
})

export default vali
